package router

import (
	"sync"

	"github.com/gin-gonic/gin"
)

var (
	mainRouterSyncOnce sync.Once
	mainRouter         *gin.Engine
)

func init() {
	SetMainRouterWorkMode(gin.DebugMode)
}

func GetMainRouter() *gin.Engine {
	mainRouterSyncOnce.Do(func() {
		mainRouter = gin.Default()
	})

	return mainRouter
}

func SetMainRouterWorkMode(mode string) {
	switch mode {
	case gin.DebugMode:
		gin.SetMode(gin.DebugMode)
	case gin.ReleaseMode:
		gin.SetMode(gin.ReleaseMode)
	case gin.TestMode:
		gin.SetMode(gin.TestMode)
	case gin.EnvGinMode:
		gin.SetMode(gin.EnvGinMode)

	default:
		gin.SetMode(gin.DebugMode)
	}

}
